package com.web.portal.utils;

//import com.hncstweb709.common.template.TemplateCode;
//import com.hncstweb709.system.mapper.SysCodeMapper;
import com.web.portal.mapper.SysCodeMapper;
import com.web.portal.utils.template.TemplateCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CodeBusiness {

    @Autowired
    private SysCodeMapper sysCodeMapper;

    /**
     * 获取code
     * @param table 数据库表名
     * @param field code 对应的字段
     * @param num code的长度
     * @return
     */
    public String getCode(String table,String field,Integer num) {
        String code = TemplateCode.getNumCode(num);
        Integer result = sysCodeMapper.checkCode(table,field,code);
        while (result > 0) {
            code = TemplateCode.getNumCode(num);
            result = sysCodeMapper.checkCode(table,field,code);
        }
        return code;
    }


}
